package graph_viewer.animator;

import java.awt.*;
import javax.swing.*;

import graph_viewer.canvas.*;
import graph_viewer.structure.*;
import graph_viewer.util.*;
/**
 * the super interface of Animator.
 * now no public method defined.
 */

public class Motion_Animator extends Basic_Animator{
	public Motion_Animator(){
	//	Debug.println( "Motion_Animator Created!", 3 );
	}

	//template hooker implementation//===================================================
	protected double find_min_move_distance(){
		return MOTION_ANIMATION_MOVE_DISTANCE;
	}

	protected double find_animation_rate(){
			return MOTION_ANIMATION_RATE;
	}
	//============================================================================		

	public boolean do_animation( Animator_Metrics a_m, Drawer_Canvas graph_canvas ){	
		//Debug.println( "Motion_Animator.do_animation!", 3 );
		Node_Position	
			from_position	= a_m.get_from_position(),
			to_position		= a_m.get_to_position();

		double
			time_interval	= a_m.get_time_interval(),
			move_interval = a_m.get_move_interval();

		Point			
			from_position_center	= from_position.find_center_point(),
			to_position_center	= to_position.find_center_point();

		boolean is_moved = move_along_line( from_position_center, to_position_center, set_up_motion_distance( from_position_center, to_position_center ) );

		Node moving_node	= graph_canvas.get_graph().search( a_m.get_node_label() );
		
		if ( is_moved ){
			
			clear_range( graph_canvas );		
			
			from_position.set_center( from_position_center );
			
			moving_node.set_position( from_position );

			Node_Position_Helper.set_cluster_node_position( moving_node, graph_canvas.get_graph() );
			
			Animator_Util.pause( MOTION_ANIMATION_TIME_INTERVAL );
			//Debug.println( "Motion_Animator: from_position_center at:" + from_position_center + " to: " + to_position_center, 3 );						
		}
		
		
		return is_moved;
	}
}//:~